﻿#region

using System;
using System.ComponentModel;
using System.Reflection;

#endregion

namespace HouseHoldBudget.Core.Extensions
{
    public static class EnumExtensions
    {
        #region Class Methods

        public static string GetDescription(this Enum value)
        {
            FieldInfo fi = value.GetType().GetField(value.ToString());
            DescriptionAttribute[] attributes =
                (DescriptionAttribute[]) fi.GetCustomAttributes(typeof (DescriptionAttribute),
                                                                false);

            return (attributes.Length > 0) ? attributes[0].Description : value.ToString();
        }

        #endregion
    }
}